subroutine find_nstop(e,r)
  use param
  use global
  implicit none
  real(dbl),intent(in) :: e
  real(dbl),intent(out) :: r
  integer :: i
  r=0
  if (e.le.nstop%mine) return
  do i=nstop%pos,1,-1
     if (e.lt.nstop%e(i)) then
        nstop%pos=i
        exit
     end if
  end do
  r=nstop%x(i)+(nstop%x(i)-nstop%x(i-1)) &
       *(e-nstop%e(i-1))/(nstop%e(i)-nstop%e(i-1))
  return
end subroutine find_nstop
